<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>
<body>
    <div class="test" ref="test" id="app">{{msg}}</div>
    <script>
        new Vue({
            el:"#app",
            data:{
                msg:"good"
            },
            // 组件被创建之前
            beforeCreate() {
                console.log("beforeCreate:"+this.$refs.test);
            },
            created() {
                console.log("created:"+this.$refs.test);
            },
            // 只能在mounted这个函数中获取DOM
            mounted(){
                console.log(this.$refs.test)
                this.$refs.test.innerHTML="hello world"

                // 测试updated
                this.msg="updated"
            },
            beforeMount() {
                console.log("beforeMount:"+this.$refs.test);
            },

            // beforeUpdate，updated都是在msg(即data数据更新的时候才或触发)
            beforeUpdate() {
                console.log("beforeUpdate");
            },
            updated() {
                console.log("updated");
            },
        })
    </script>
</body>
</html>